// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PackageId.cs" company="In The Hand Ltd">
//   Copyright (c) 2013-14 In The Hand Ltd, All rights reserved.
// </copyright>
// <summary>
//   Provides package identification info, such as name, version, and publisher.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace InTheHand.ApplicationModel
{
    using System;
    using Windows.ApplicationModel;

    /// <summary>
    /// Provides package identification info, such as name, version, and publisher.
    /// </summary>
    public sealed class PackageId
    {
        // for 8.1 only
        private Windows.ApplicationModel.PackageId id;

        internal PackageId(Windows.ApplicationModel.PackageId id)
        {
            this.id = id;
        }

        internal PackageId()
        {
        }

        private string author;
        /// <summary>
        /// Gets the value of the Author attribute for the specified application package.
        /// <para>Windows Phone only</para>
        /// </summary>
        public string Author
        {
            get
            {
                return author;
            }

            internal set
            {
                author = value;
            }
        }

        private string fullName;
        /// <summary>
        /// Gets the full name of the package.
        /// </summary>
        public string FullName
        {
            get
            {
                if(id != null)
                {
                    return id.FullName;
                }

                return fullName;
            }

            internal set
            {
                fullName = value;
            }
        }

        private string name;
        /// <summary>
        /// Gets the name of the package.
        /// </summary>
        /// <value>The package name.</value>
        public string Name
        {
            get
            {
                if(id != null)
                {
                    return id.Name;
                }

                return name;
            }

            internal set
            {
                name = value;
            }
        }

        /// <summary>
        /// Gets the value of the ProductID attribute associated with this application package.
        /// </summary>
        /// <value>The value of the ProductID attribute associated with this application package.</value>
        public string ProductId 
        { 
            get
            {
                return Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
            }
        }

        private string publisher;
        /// <summary>
        /// Gets the publisher of the package.
        /// </summary>
        /// <value>The publisher.</value>
        public string Publisher
        {
            get
            {
                if(id != null)
                {
                    return id.Publisher;
                }

                return publisher;
            }

            internal set
            {
                publisher = value;
            }
        }

        private string publisherId;
        /// <summary>
        /// Gets the publisher ID of the package.
        /// </summary>
        public string PublisherId
        {
            get
            {
                if(id != null)
                {
                    return id.PublisherId;
                }

                return publisherId;
            }

            internal set
            {
                publisherId = value;
            }
        }

        private PackageVersion version;
        /// <summary>
        /// Gets the package version info.
        /// </summary>
        /// <value>The package version information.</value>
        [CLSCompliant(false)]
        public PackageVersion Version
        {
            get
            {
                if(id != null)
                {
                    return id.Version;
                }

                return version;
            }

            internal set
            {
                version = value;
            }
        }
    }
}